home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group96a.txt / 000178_icon-group-sender _Thu Aug 8 21:45:53 1996.msg < prev    next >
Internet Message Format  |  1996-09-05  |  4KB

  1. Received: by cheltenham.cs.arizona.edu; Mon, 12 Aug 1996 07:46:34 MST
  2. Date: Thu, 8 Aug 96 21:45:53 CDT
  3. From: yak@comm.mot.com (Yarko Tymciurak)
  4. Message-Id: <9608090245.AA06361@platov8>
  5. To: X041RS@tamvm1.tamu.edu, icon-group@cs.arizona.edu
  6. Subject: Re:  dos system call
  7. Errors-To: icon-group-errors@cs.arizona.edu
  8. Status: O
  9.  
  10. | Errors-To: icon-group-errors@cs.arizona.edu
  11. | Date:         Tue, 06 Aug 96 15:25:19 CDT
  12. | From: Roger Sorrells <X041RS@tamvm1.tamu.edu>
  13. | Subject:      dos system call
  14. | To: icon-group@cs.arizona.edu
  15. | Errors-To: icon-group-errors@cs.arizona.edu
  16. | when I include the lines
  17. | system("set")       #1
  18. | system("set x=y")   #2
  19. | system("set")       #3
  20. |  in a program, I get the same output from #3 as from #1,
  21. |  no additional X=y among the environment variables.
  22. | How do I set DOS environment variables from within an Icon program?
  23. | I am using MS-DOS 6.21 and Icon 8.10
  24.  
  25. (Now, for some totally deviant technical bable, from
  26.  old brain cells, loaded a long time ago.  Memory may be corrupt
  27.  or out of date after a dozen years or so since last refresh...
  28.  ...far more than you wanted to know...enjoy...)
  29.  
  30. Actually, every process (Unix and DOS) get's it's own copy of the
  31. parent process environment (what good is setting the environment
  32. of a parent process where there are hundreds of child processes,
  33. for example?).
  34.  
  35. As a process, it makes sense that you only get to change what you
  36. see, and what affects you or your children processes.
  37.  
  38. When you use "SET" in DOS, you are - in effect - using a built-in
  39. shell command that sets that shell's own environment.  Ergo,
  40. system("set...") only sets the environment of the running process.
  41. Under a system command, you can't even inspect with your
  42. Icon process, since "system" is a call to a new shell- a child of
  43. the calling Icon process.  It get's a copy of you're Icon environment,
  44. which explains your example (each "system" call is a new process, each
  45. with its own copy of the Icon environment - which isn't changed
  46. anywhere between system calls).  Icon has a getenv() function, but
  47. no corresponding setenv() as far as I recall, so you can't change
  48. the environment you pass to children this way.
  49.  
  50. Now, since DOS is single tasking, and since it's process memory
  51. allocation is a simple, singly linked list (last I checked ...),
  52. it is possible (and unsupported) to change the "master" (that is,
  53. boot-shell's) environment.  With pointers, you can find the
  54. memory allocation header to your process's environment, and
  55. thread (really, search) your way through lower memory until you
  56. find the master (which is different from child environment memory
  57. allocation headers in that - if I remember - the pointer to the
  58. next memory block is to lower instead of higher memory).
  59.  
  60. This is REALLY goofy stuff (and fun!).  The only reason I know -
  61. I put together a command that read a port and saved info on what
  62. was on that port in an environment var once upon a midnight
  63. dreary....  (Someone told me there was no way to do it, so I had
  64. to).  Since memory is allocated in some finite chunks (used to be
  65. 16 bytes), you have to be careful not to overwrite other memory.
  66. The DOS environment is a contiguous byte string, and you can't ever
  67. be sure if you'll have any memory to play with at the end of an
  68. allocation chain.   Therefor, you can only change existing
  69. environment variables (or overwrite space used by existing ones),
  70. and practically can't set them to anything longer than what
  71. they are already set to.   If that's useful (changing characters,
  72. "a" to "b", for example)....
  73.  
  74. ...it can be done (not any "simple" way I can see in Icon), but
  75.    you don't want to do it!
  76.  
  77. Older, and wiser (?),
  78.  
  79. Yarko.
  80.